package com.bryantkobe.myspringcode.exception.massert;

import com.bryantkobe.myspringcode.exception.BusinessException;

import java.util.function.Function;

/**
 * @description: 业务异常断言
 * @author: alienwarezzl
 * @date: 2025/9/22
 */
public interface BusinessExceptionAssert extends Function<String, BusinessException> {

    String getErrorCode();
    String getDefaultMessage();

    default BusinessException apply(String message) {
        return new BusinessException(getErrorCode(),
                message != null ? message : getDefaultMessage());
    }

    default void assertTrue(boolean condition, String message) {
        if (!condition) {
            throw apply(message);
        }
    }

    default void notNull(Object obj, String message) {
        if (obj == null) {
            throw apply(message);
        }
    }
}
